package com.sub.service.impl;

import com.sub.mapper.SpSecondMenuMapper;
import com.sub.model.SpSecondMenu;
import com.sub.service.SecondMenuService;
import com.sub.utils.PageList;
import org.n3r.idworker.Sid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SecondMenuServiceImpl implements SecondMenuService{

	@Autowired
	private SpSecondMenuMapper spSecondMenuMapper;

	@Autowired
	private Sid sid;



	@Override
	public List<SpSecondMenu> querySecondMenuList(SpSecondMenu spSecondMenu) {
		return spSecondMenuMapper.select(spSecondMenu);
	}

	@Override
	public SpSecondMenu queryOne(String spSecondMenuId) {
		return spSecondMenuMapper.selectByPrimaryKey(spSecondMenuId);
	}

	@Override
	public PageList querySecondMenuByPageAndName(PageList pageList,int page, String name) {
		int size = pageList.getSize();
        pageList.setTotal(spSecondMenuMapper.selectCountS(name));
        pageList.setList(spSecondMenuMapper.getSecondMenuForPage(name,(page-1)*size,size));
		return pageList;
	}

	@Override
	public int saveSecond(SpSecondMenu secondMenu) {
		secondMenu.setSpSecondMenuId(sid.nextShort());
		return spSecondMenuMapper.insert(secondMenu);
	}

	@Override
	public int editSecond(SpSecondMenu secondMenu) {
		return spSecondMenuMapper.updateByPrimaryKeySelective(secondMenu);
	}

	@Override
	public int removeSecondById(String secondMenuId) {
		return spSecondMenuMapper.deleteByPrimaryKey(secondMenuId);
	}

	@Override
	public int batchRemoveSecondByIdS(String[] ids) {
		return spSecondMenuMapper.batchRemoveSecondByIdS(ids);
	}
}
